package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.dictionarydata.DictionaryCodeData;
import com.jinmdz.fmis.api.admin.model.dictionarydata.DictionaryListItem;
import com.jinmdz.fmis.api.admin.model.servicedictionary.ServiceDictionaryDataIdData;
import com.jinmdz.fmis.api.admin.model.servicedictionary.ServiceDictionaryDataLoadData;
import com.jinmdz.fmis.api.admin.model.servicedictionary.ServiceDictionaryDataSaveData;
import com.jinmdz.fmis.api.admin.service.ServiceDictionaryService;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.admin.model.servicedictionary.ServiceDictionaryDataListItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 字典费用关联及计算规则设置相关接口
 *
 * @author GuanKui
 * @date 2020/3/11 13:07
 */
@Api(description = "字典费用关联及计算规则设置相关接口")
@RestController()
@RequestMapping("/admin/service-dictionary")
public class ServiceDictionaryController extends BaseController {

    @Resource
    private ServiceDictionaryService serviceDictionaryService;

    /**
     * 加载要与费用和规则绑定的字典类型信息列表
     *
     * @param
     * @return
     * @author GuanKui
     * @date 2020/3/9  15:05
     */
    @ApiOperation(value = "加载要与费用和规则绑定的字典类型信息列表", notes = "加载字典类型信息列表，字典类型仅包括车辆类型【transport_car_type】" +
            "、冷藏柜类型【equipment_type】、礼厅类型【mourn_type】、火化炉型【furnace_type】")
    @PostMapping("/load-service-dictionary-list")
    public BaseResult<ArrayList<DictionaryListItem>> loadServiceDictionaryList() {
        return resultHandler(userItem -> serviceDictionaryService.loadServiceDictionaryList());
    }

    /**
     * 根据字典编码加载字典下的数据项列表
     *
     * @param data 字典编码
     * @return
     * @author GuanKui
     * @date 2020/3/12  11:28
     */
    @ApiOperation(value = "根据字典编码加载字典下的数据项列表", notes = "根据表【data_dictionary】中字典编码【dict_code】加载字典下的数据项列表")
    @PostMapping("/load-service-dictionary-data-list-with-code")
    public BaseResult<ArrayList<ServiceDictionaryDataListItem>> loadServiceDictionaryDataListWithCode(@RequestBody DictionaryCodeData data) {
        return resultHandler(data, userItem -> serviceDictionaryService.loadServiceDictionaryDataListWithCode(data));
    }

    /**
     * 加载字典、费用、规则数据信息
     *
     * @param data 主键
     * @return
     * @author GuanKui
     * @date 2020/3/12  15:06
     */
    @ApiOperation(value = "加载字典、费用、规则数据信息", notes = "根据，加载字典、费用、规则数据信息，规则信息修改成只加载与当前业务相关的")
    @PostMapping("/load-service-dictionary-data-with-id")
    public BaseResult<ServiceDictionaryDataLoadData> loadServiceDictionaryDataWithId(@RequestBody ServiceDictionaryDataIdData data) {
        return resultHandler(data, userItem -> serviceDictionaryService.loadServiceDictionaryDataWithId(data));
    }

    /**
     * 保存字典、费用、规则数据信息
     *
     * @param data 保存数据
     * @return
     * @author GuanKui
     * @date 2020/3/12  15:38
     */
    @ApiOperation(value = "保存字典、费用、规则数据信息", notes = "保存字典、费用、规则数据信息到表【service_dictionary_item】中")
    @PostMapping("/save-service-dictionary-data")
    public BaseResult saveServiceDictionaryData(@RequestBody ServiceDictionaryDataSaveData data) {
        return resultHandler(data, userItem -> serviceDictionaryService.saveServiceDictionaryData(userItem, data));
    }

    /**
     * 删除字典、费用、规则数据关联信息
     *
     * @param data 主键和数据版本
     * @return
     * @author GuanKui
     * @date 2020/3/12  15:06
     */
    @ApiOperation(value = "删除字典、费用、规则数据关联信息", notes = "根据，加载字典、费用、规则数据信息")
    @PostMapping("/delete-service-dictionary-data-with-id")
    public BaseResult deleteServiceDictionaryDataWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> serviceDictionaryService.deleteServiceDictionaryDataWithId(userItem, data));
    }

}

